// pages/lead_packets/lead_packets.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    clock: getApp().globalData.source + 'ttbt_image_icon/1.png',
    clock2: getApp().globalData.source + 'ttbt_image_icon/2.png',
    clock3: getApp().globalData.source + 'ttbt_image_icon/3.png',
    clock4: getApp().globalData.source + 'ttbt_image_icon/4.png',
    indicatorDots: true,
    autoplay: false,
    interval: 5000,
    duration: 200,
    vertical: true,
    circular:true,
	topbg: getApp().globalData.source + 'ttbt_image_icon/topbg.png',
  },
  withdraw: function () {
    wx.navigateTo({
      url: '../my/mydetail/mydetail',
    })
  },

  gohome: function () {
    wx.switchTab({
      url: '/pages/style/style',
    })
  },
  tozhuli: function () {
    wx.navigateTo({
      url: '../day_day_listen/sharelist/sharelist',
    })
  },
  tobenfitsdetails: function () {
    wx.navigateTo({
      url: '../my/mydetail/mydetail',
    })
  },

  tohome: function () {
    wx.switchTab({
      url: '../style/style',
    })
  },
  rule: function () {
    wx.navigateTo({
      url: '/pages/activity/activity-rule/activity-rule',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var vm = this
    var showhomeicon = options.showhomeicon == "fx" ? true : ""; //判断是分享页进入还是小程序正常进入
    console.log(showhomeicon)
    if (showhomeicon) {
      this.setData({
        showhomeicon: showhomeicon
      })
    }
    var data = {}
    var userIds = wx.getStorageSync("userId") === "" ? -1 : wx.getStorageSync("userId");
    getApp().request(getApp().globalData.https + "/orderResource/walletBalance/" + userIds,
      "get", data,
      function (res) {
        if (res.code == 0) {
          vm.setData({
            info: res.data,
          })
        }
      },
      function (res) { });
    getApp().request(getApp().globalData.https + "/orderResource/exchangeRate",
      "get", data,
      function (res) {
        if (res.code == 0) {
          var data = res.data.shift();
          console.log(JSON.stringify(data))
          vm.setData({
            rate: data
          })
        }
      },
      function (res) { });


    var vm = this
    var data = {
      userId: wx.getStorageSync("userId")
    }
    getApp().requestLoading(getApp().globalData.https + "programResource/supportTingCount/" + wx.getStorageSync("userId"),
      "get", data, "加载中..",
      function (res) {
        console.log(res)
        vm.setData({
          zhuli: res.data
        })
      }
    )


    var vm = this
    var data = {
      userId: wx.getStorageSync("userId")
    }
    getApp().request(getApp().globalData.https + "hd/find/listen/length",
      "post", data,
      function (res) {
        vm.setData({
          tbinfo: res,
        })

        //根据收听的时长显示响应的图片
        if (Math.round(res.sumTime / 60) <= 10) {

        } else if (Math.round(res.sumTime / 60) > 10 && Math.round(res.sumTime / 60) <= 30) {
          vm.setData({
            clock: vm.data.clock2
          })
        } else if (Math.round(res.sumTime / 60) > 30 && Math.round(res.sumTime / 60) <= 60) {
          vm.setData({
            clock: vm.data.clock3
          })
        } else if (Math.round(res.sumTime / 60) > 60 && Math.round(res.sumTime / 60) <= 90) {
          vm.setData({
            clock: vm.data.clock3
          })
        } else {
          vm.setData({
            clock: vm.data.clock4
          })
        }
      }
    )
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
  * 用户点击右上角分享
  */
  onShareAppMessage: function (e) {
    var that = this;
    var userIds = wx.getStorageSync("userId")
    return {
      path: "/pages/lead_packets/lead_packets?showhomeicon=fx",
      success(res) {
        console.log("success")
      },
      fail(e) {
        console.log("fail")
      },
      //分享完成
      complete() {
        console.log("complete")
      }
    }
  },

})